package xyz.msj.hrm.util;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.MimeMessageHelper;

import javax.mail.MessagingException;
import javax.mail.internet.MimeMessage;
import java.io.File;

/**
 * 创建复杂邮件
 */
public class CreateEmail {

    @Autowired
    private JavaMailSender javaMailSender;

    public  void createEmail(){
        try {
            //创建复杂邮件对象
            MimeMessage mimeMessage = javaMailSender.createMimeMessage();
            //复杂邮件工具类
            MimeMessageHelper helper = new MimeMessageHelper(mimeMessage,true,"utf-8");
            //发件人
            helper.setFrom("1162443647@qq.com");
            //邮件标题
            helper.setSubject("有新课程上线啦");
            //邮件内容
            helper.setText(" <a href=\"http://localhost:8080/#/login\">\n" +
                    "      <img src=\"http://118.25.154.214:8888/group1/M00/00/0E/dhma1l9gxgiAQ6cIAADAt8KxFvc32.jpeg\" width=\"300px\" alt=\"不存在\">\n" +
                    "      跳转到登录页面，我们非常高兴您的成功入驻，希望我们的合作能互利互赢，期待和您见面！\n" +
                    "    </a>",true);
            //附件
            helper.addAttachment("宠物.jpg", new File("E:\\图片\\6.jpg"));

            //收件人
            helper.setTo("aine1113@163.com");
            //发送邮件
            javaMailSender.send(mimeMessage);
        } catch (MessagingException e) {
            e.printStackTrace();
        }
    }



}
